package com.chinasofti.zbest.web;

import com.chinasofti.zbest.dao.model.Product;
import com.chinasofti.zbest.service.info.CategoryInfo;
import com.chinasofti.zbest.service.ICategoryService;
import com.chinasofti.zbest.service.IProductService;
import com.chinasofti.zbest.service.info.ProductInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@Slf4j
public class IndexController {

    @Autowired
    private IProductService productService;
    @Autowired
    private ICategoryService categoryService;

    @RequestMapping("/")
    public String welcome(ModelMap modelMap, HttpSession session) {
        /**
         *加载数据
         * 1.加载分类
         */
//        Collection<Category> categories=categoryService.listByMap(new HashMap<>());
        List<CategoryInfo> categories=categoryService.getAllCategoryInfo();
        log.info("{}",categories);
        session.setAttribute("categories",categories);
        /**
         * 更多推荐
         */
        log.info("存放数量");
        List<Product> topSell=productService.findSell(3);
        System.out.println(topSell);
        log.info("{}",topSell);
        session.setAttribute("topSell",topSell);

        log.info("显示创意家居");
        List<Product> findAll=productService.searchIdea(22);
        modelMap.addAttribute("findAll",findAll);
        log.info("{}",findAll);

        log.info("布艺软式");
        List<ProductInfo> wallsAll=productService.searchCategoryId(9);
        modelMap.addAttribute("wallsAll",wallsAll.subList(0,3));
        log.info("{}",wallsAll);

        log.info("墙式壁桂");
        List<ProductInfo> boLocks=productService.searchCategoryId(1);
        modelMap.addAttribute("boLocks",boLocks.subList(1,4));
        log.info("{}",boLocks);

        log.info("装饰摆件");
        List<ProductInfo> boLock=productService.searchCategoryId(4);
        modelMap.addAttribute("boLock",boLock.subList(0,3));
        log.info("{}",boLock);

        log.info("蜡艺香薰");
        List<ProductInfo> decorate=productService.searchCategoryId(13);
        modelMap.addAttribute("decorate",decorate.subList(1,4));
        log.info("{}",decorate);

        return "index";
    }

}